package com.kuaiyin.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.handlers.FastjsonTypeHandler;
import com.kuaiyin.sampling.BaseEntity;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

import java.io.Serial;
import java.io.Serializable;
import java.util.Map;

/**
 * <p>
 * 接口请求定义表（支持动态模板）
 * </p>
 *
 * @author ng
 * @since 2025-04-25
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName(value = "request", autoResultMap = true)
@Schema(name = "Request", description = "接口请求定义表（支持动态模板）")
public class Request extends BaseEntity implements Serializable {

    @Serial
    private static final long serialVersionUID = 1L;

    @Schema(description = "主键ID")
    @TableId(value = "id", type = IdType.AUTO)
    private Long id;

    @Schema(description = "请求名称（唯一）", example = "查询用户接口")
    private String name;

    @Schema(description = "接口路径（支持模板，如/api/v1/user/{id}）",
            example = "/api/v1/users/{userId}")
    private String path;

    @Schema(description = "HTTP方法",
            example = "GET",
            allowableValues = {"GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS"})
    private String method;

    @Schema(description = "请求头（JSON格式，支持{{变量}}和{{$函数}}）",
            example = "{\"Content-Type\":\"application/json\",\"Authorization\":\"Bearer {{token}}\"}")
    @TableField(typeHandler = FastjsonTypeHandler.class)
    private Map<String, Object> headers;

    @Schema(description = "查询参数（JSON格式，支持动态模板）",
            example = "{\"page\":1,\"size\":10}")
    @TableField(typeHandler = FastjsonTypeHandler.class)
    private Map<String, Object> params;

    @Schema(description = "请求体（JSON格式，支持动态模板函数）",
            example = "{\"name\":\"{{$randomName}}\",\"phone\":\"{{$randomPhone}}\"}")
    @TableField(typeHandler = FastjsonTypeHandler.class)
    private Map<String, Object> body;

    @Schema(description = "接口描述", example = "用户相关接口定义")
    private String description;
}